T
Chili.Opf3 Send comments on this topic.
Generic GetObject(PersistentTypeSelector,String,Object[]) Method
See Also  Example
Chili.Opf3 Namespace > ObjectContext Class > GetObject Method : Generic GetObject(PersistentTypeSelector,String,Object[]) Method




typeSelector
Delegate invoked before each creating of a persistent object. This allows to dynamically change the type of the created persistent object or ignore some objects.
conditions
A condition string that specifies the object that is loaded.
parameters
A list of parameter that is passed as parameter for the conditions.
Fetches the first object matching the conditions and returns it.

Syntax

Visual Basic (Declaration) 
Overloads Public Overridable Function GetObject(Of T)( _
   ByVal typeSelector As PersistentTypeSelector, _
   ByVal conditions As String, _
   ByVal ParamArray parameters() As Object _
) As T
Visual Basic (Usage)Copy Code
Dim instance As ObjectContext
Dim typeSelector As PersistentTypeSelector
Dim conditions As String
Dim parameters() As Object
Dim value As T
 
value = instance.GetObject(Of T)(typeSelector, conditions, parameters)
C# 
public virtual T GetObject<T>( 
   PersistentTypeSelector typeSelector,
   string conditions,
   params object[] parameters
)
Managed Extensions for C++ 
public: virtual T GetObject<T>( 
   PersistentTypeSelector* typeSelector,
   string* conditions,
   params Object*[]* parameters
) 
C++/CLI 
public:
virtual T GetObjectgeneric<typename T>
( 
   PersistentTypeSelector^ typeSelector,
   String^ conditions,
   ... array<Object^>^ parameters
) 

Parameters

typeSelector
Delegate invoked before each creating of a persistent object. This allows to dynamically change the type of the created persistent object or ignore some objects.
conditions
A condition string that specifies the object that is loaded.
parameters
A list of parameter that is passed as parameter for the conditions.

Type Parameters

T

Return Value

The first object matching the conditions.

Example

The following example introduces to the use of the GetObject routine.
C#Copy Code
// Creates a new ObjectContext that uses an MsSql Server as storage. 
ObjectContext context = new ObjectContext(new MsSqlStorage("sa", "",  
    "localhost", "application")); 
  
// ... Other code. 
  
// Get the first user matching the name and sorts them by name. 
User user = context.GetObject<User>(new PersistentTypeSelector(MySelection), 
    "Name like {0} SortBy Name Asc", "%mith%"); 
  
// If the user object is null nothing that matches has been found. 
if (user == null) 
    Debug.WriteLine("No object found!"); 
else 
    Debug.WriteLine( 
        string.Format("Object with name {0} has been found.",  
        user.Name)); 
 
// ... 
 
private void MySelection(object sender, FetchingStorageRecordEventArgs e) 

    if (e.DataRecord["Type"] == "1") 
    { 
        // Switch the type of the persistent that is created to User1. 
        e.Type = typeof(User1); 
    } 
    // Have a persistent of type User created. 
    e.Type = typeof(User); 

    

Remarks

Executes a query on the storage and returns the first object that matches the query. If no object is found Null is returned.

Requirements

Platforms: Windows 2000, Windows XP family, Windows Server 2003 family, Windows Vista family

See Also